{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "%matplotlib inline\n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<style>body {\n",
       "    margin: 0;\n",
       "    font-family: Helvetica;\n",
       "}\n",
       "table.dataframe {\n",
       "    border-collapse: collapse;\n",
       "    border: none;\n",
       "}\n",
       "table.dataframe tr {\n",
       "    border: none;\n",
       "}\n",
       "table.dataframe td, table.dataframe th {\n",
       "    margin: 0;\n",
       "    border: 1px solid white;\n",
       "    padding-left: 0.25em;\n",
       "    padding-right: 0.25em;\n",
       "}\n",
       "table.dataframe th:not(:empty) {\n",
       "    background-color: #fec;\n",
       "    text-align: left;\n",
       "    font-weight: normal;\n",
       "}\n",
       "table.dataframe tr:nth-child(2) th:empty {\n",
       "    border-left: none;\n",
       "    border-right: 1px dashed #888;\n",
       "}\n",
       "table.dataframe td {\n",
       "    border: 2px solid #ccf;\n",
       "    background-color: #f4f4ff;\n",
       "}\n",
       "h3 {\n",
       "    color: white;\n",
       "    background-color: black;\n",
       "    padding: 0.5em;\n",
       "}\n",
       "</style>"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from IPython.core.display import HTML\n",
    "css = open('style-table.css').read() + open('style-notebook.css').read()\n",
    "HTML('<style>{}</style>'.format(css))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div style=\"max-height:1000px;max-width:1500px;overflow:auto;\">\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>title</th>\n",
       "      <th>year</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Tomorrow Ends at Dawn</td>\n",
       "      <td>2002</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Brothers of the West</td>\n",
       "      <td>1937</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Nemo</td>\n",
       "      <td>1984</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Pereezd</td>\n",
       "      <td>2014</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Bad for Business</td>\n",
       "      <td>2007</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                   title  year\n",
       "0  Tomorrow Ends at Dawn  2002\n",
       "1   Brothers of the West  1937\n",
       "2                   Nemo  1984\n",
       "3                Pereezd  2014\n",
       "4       Bad for Business  2007"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "titles = pd.read_csv('data/titles.csv')\n",
    "titles.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div style=\"max-height:1000px;max-width:1500px;overflow:auto;\">\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>title</th>\n",
       "      <th>year</th>\n",
       "      <th>name</th>\n",
       "      <th>type</th>\n",
       "      <th>character</th>\n",
       "      <th>n</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Suuri illusioni</td>\n",
       "      <td>1985</td>\n",
       "      <td>Homo $</td>\n",
       "      <td>actor</td>\n",
       "      <td>Guests</td>\n",
       "      <td>22</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Gangsta Rap: The Glockumentary</td>\n",
       "      <td>2007</td>\n",
       "      <td>Too $hort</td>\n",
       "      <td>actor</td>\n",
       "      <td>Himself</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Menace II Society</td>\n",
       "      <td>1993</td>\n",
       "      <td>Too $hort</td>\n",
       "      <td>actor</td>\n",
       "      <td>Lew-Loc</td>\n",
       "      <td>27</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Porndogs: The Adventures of Sadie</td>\n",
       "      <td>2009</td>\n",
       "      <td>Too $hort</td>\n",
       "      <td>actor</td>\n",
       "      <td>Bosco</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Stop Pepper Palmer</td>\n",
       "      <td>2014</td>\n",
       "      <td>Too $hort</td>\n",
       "      <td>actor</td>\n",
       "      <td>Himself</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                               title  year       name   type character   n\n",
       "0                    Suuri illusioni  1985     Homo $  actor    Guests  22\n",
       "1     Gangsta Rap: The Glockumentary  2007  Too $hort  actor   Himself NaN\n",
       "2                  Menace II Society  1993  Too $hort  actor   Lew-Loc  27\n",
       "3  Porndogs: The Adventures of Sadie  2009  Too $hort  actor     Bosco   3\n",
       "4                 Stop Pepper Palmer  2014  Too $hort  actor   Himself NaN"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cast = pd.read_csv('data/cast.csv')\n",
    "cast.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "209286"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# How many movies are listed in the titles dataframe?\n",
    "\n",
    "len(titles)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div style=\"max-height:1000px;max-width:1500px;overflow:auto;\">\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>title</th>\n",
       "      <th>year</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2756</th>\n",
       "      <td>Miss Jerry</td>\n",
       "      <td>1894</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>132322</th>\n",
       "      <td>Reproduction of the Corbett and Fitzsimmons Fight</td>\n",
       "      <td>1897</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                    title  year\n",
       "2756                                           Miss Jerry  1894\n",
       "132322  Reproduction of the Corbett and Fitzsimmons Fight  1897"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# What are the earliest two films listed in the titles dataframe?\n",
    "\n",
    "titles.sort_values('year').head(2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "19"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# How many movies have the single-word title \"Hamlet\"?\n",
    "\n",
    "len(titles[titles.title == 'Hamlet'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# How many movies are titled \"North by Northwest\"?\n",
    "\n",
    "len(titles[titles.title == 'North by Northwest'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div style=\"max-height:1000px;max-width:1500px;overflow:auto;\">\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>title</th>\n",
       "      <th>year</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>119520</th>\n",
       "      <td>Hamlet</td>\n",
       "      <td>1910</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         title  year\n",
       "119520  Hamlet  1910"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# When was the first movie titled \"Hamlet\" made?\n",
    "\n",
    "titles[titles.title == 'Hamlet'].sort_values('year').head(1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div style=\"max-height:1000px;max-width:1500px;overflow:auto;\">\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>title</th>\n",
       "      <th>year</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>89106</th>\n",
       "      <td>Treasure Island</td>\n",
       "      <td>1918</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>196051</th>\n",
       "      <td>Treasure Island</td>\n",
       "      <td>1920</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>154459</th>\n",
       "      <td>Treasure Island</td>\n",
       "      <td>1934</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>174074</th>\n",
       "      <td>Treasure Island</td>\n",
       "      <td>1950</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>72215</th>\n",
       "      <td>Treasure Island</td>\n",
       "      <td>1972</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>66550</th>\n",
       "      <td>Treasure Island</td>\n",
       "      <td>1973</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18201</th>\n",
       "      <td>Treasure Island</td>\n",
       "      <td>1985</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>80930</th>\n",
       "      <td>Treasure Island</td>\n",
       "      <td>1999</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                  title  year\n",
       "89106   Treasure Island  1918\n",
       "196051  Treasure Island  1920\n",
       "154459  Treasure Island  1934\n",
       "174074  Treasure Island  1950\n",
       "72215   Treasure Island  1972\n",
       "66550   Treasure Island  1973\n",
       "18201   Treasure Island  1985\n",
       "80930   Treasure Island  1999"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# List all of the \"Treasure Island\" movies from earliest to most recent.\n",
    "\n",
    "titles[titles.title == 'Treasure Island'].sort_values('year')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1029"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# How many movies were made in the year 1950?\n",
    "\n",
    "len(titles[titles.year == 1950])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1419"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# How many movies were made in the year 1960?\n",
    "\n",
    "len(titles[titles.year == 1960])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "11989"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# How many movies were made from 1950 through 1959?\n",
    "\n",
    "t = titles\n",
    "len(t[(t.year >= 1950) & (t.year <= 1959)])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "11989"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(t[t.year // 10 == 195])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div style=\"max-height:1000px;max-width:1500px;overflow:auto;\">\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>title</th>\n",
       "      <th>year</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>535</th>\n",
       "      <td>Batman</td>\n",
       "      <td>1943</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>132676</th>\n",
       "      <td>Batman</td>\n",
       "      <td>1989</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         title  year\n",
       "535     Batman  1943\n",
       "132676  Batman  1989"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# In what years has a movie titled \"Batman\" been released?\n",
    "\n",
    "t = titles\n",
    "t[t.title == 'Batman']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "72"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# How many roles were there in the movie \"Inception\"?\n",
    "\n",
    "c = cast\n",
    "len(c[c.title == 'Inception'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "21"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# How many roles in the movie \"Inception\" are NOT ranked by an \"n\" value?\n",
    "\n",
    "c = cast\n",
    "c = c[c.title == 'Inception']\n",
    "c = c[c.n.isnull()]\n",
    "len(c)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "51"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# But how many roles in the movie \"Inception\" did receive an \"n\" value?\n",
    "\n",
    "c = cast\n",
    "c = c[c.title == 'Inception']\n",
    "c = c[c.n.notnull()]\n",
    "len(c)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div style=\"max-height:1000px;max-width:1500px;overflow:auto;\">\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>title</th>\n",
       "      <th>year</th>\n",
       "      <th>name</th>\n",
       "      <th>type</th>\n",
       "      <th>character</th>\n",
       "      <th>n</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>757365</th>\n",
       "      <td>North by Northwest</td>\n",
       "      <td>1959</td>\n",
       "      <td>Cary Grant</td>\n",
       "      <td>actor</td>\n",
       "      <td>Roger O. Thornhill</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3017825</th>\n",
       "      <td>North by Northwest</td>\n",
       "      <td>1959</td>\n",
       "      <td>Eva Marie Saint</td>\n",
       "      <td>actress</td>\n",
       "      <td>Eve Kendall</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1265989</th>\n",
       "      <td>North by Northwest</td>\n",
       "      <td>1959</td>\n",
       "      <td>James Mason</td>\n",
       "      <td>actor</td>\n",
       "      <td>Phillip Vandamm</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2716993</th>\n",
       "      <td>North by Northwest</td>\n",
       "      <td>1959</td>\n",
       "      <td>Jessie Royce Landis</td>\n",
       "      <td>actress</td>\n",
       "      <td>Clara Thornhill</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>308625</th>\n",
       "      <td>North by Northwest</td>\n",
       "      <td>1959</td>\n",
       "      <td>Leo G. Carroll</td>\n",
       "      <td>actor</td>\n",
       "      <td>The Professor</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2627970</th>\n",
       "      <td>North by Northwest</td>\n",
       "      <td>1959</td>\n",
       "      <td>Josephine Hutchinson</td>\n",
       "      <td>actress</td>\n",
       "      <td>Mrs. Townsend</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1473804</th>\n",
       "      <td>North by Northwest</td>\n",
       "      <td>1959</td>\n",
       "      <td>Philip Ober</td>\n",
       "      <td>actor</td>\n",
       "      <td>Lester Townsend</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1107146</th>\n",
       "      <td>North by Northwest</td>\n",
       "      <td>1959</td>\n",
       "      <td>Martin Landau</td>\n",
       "      <td>actor</td>\n",
       "      <td>Leonard</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2122318</th>\n",
       "      <td>North by Northwest</td>\n",
       "      <td>1959</td>\n",
       "      <td>Adam Williams</td>\n",
       "      <td>actor</td>\n",
       "      <td>Valerian</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1573755</th>\n",
       "      <td>North by Northwest</td>\n",
       "      <td>1959</td>\n",
       "      <td>Edward Platt</td>\n",
       "      <td>actor</td>\n",
       "      <td>Victor Larrabee</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>578418</th>\n",
       "      <td>North by Northwest</td>\n",
       "      <td>1959</td>\n",
       "      <td>Robert Ellenstein</td>\n",
       "      <td>actor</td>\n",
       "      <td>Licht</td>\n",
       "      <td>11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1990909</th>\n",
       "      <td>North by Northwest</td>\n",
       "      <td>1959</td>\n",
       "      <td>Les Tremayne</td>\n",
       "      <td>actor</td>\n",
       "      <td>Auctioneer</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>402492</th>\n",
       "      <td>North by Northwest</td>\n",
       "      <td>1959</td>\n",
       "      <td>Philip Coolidge</td>\n",
       "      <td>actor</td>\n",
       "      <td>Dr. Cross</td>\n",
       "      <td>13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1311473</th>\n",
       "      <td>North by Northwest</td>\n",
       "      <td>1959</td>\n",
       "      <td>Patrick McVey</td>\n",
       "      <td>actor</td>\n",
       "      <td>Sergeant Flamm</td>\n",
       "      <td>14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>176953</th>\n",
       "      <td>North by Northwest</td>\n",
       "      <td>1959</td>\n",
       "      <td>Edward Binns</td>\n",
       "      <td>actor</td>\n",
       "      <td>Captain Junket</td>\n",
       "      <td>15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1202896</th>\n",
       "      <td>North by Northwest</td>\n",
       "      <td>1959</td>\n",
       "      <td>Ken Lynch</td>\n",
       "      <td>actor</td>\n",
       "      <td>Charley - Chicago Policeman</td>\n",
       "      <td>16</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                      title  year                  name     type  \\\n",
       "757365   North by Northwest  1959            Cary Grant    actor   \n",
       "3017825  North by Northwest  1959       Eva Marie Saint  actress   \n",
       "1265989  North by Northwest  1959           James Mason    actor   \n",
       "2716993  North by Northwest  1959   Jessie Royce Landis  actress   \n",
       "308625   North by Northwest  1959        Leo G. Carroll    actor   \n",
       "2627970  North by Northwest  1959  Josephine Hutchinson  actress   \n",
       "1473804  North by Northwest  1959           Philip Ober    actor   \n",
       "1107146  North by Northwest  1959         Martin Landau    actor   \n",
       "2122318  North by Northwest  1959         Adam Williams    actor   \n",
       "1573755  North by Northwest  1959          Edward Platt    actor   \n",
       "578418   North by Northwest  1959     Robert Ellenstein    actor   \n",
       "1990909  North by Northwest  1959          Les Tremayne    actor   \n",
       "402492   North by Northwest  1959       Philip Coolidge    actor   \n",
       "1311473  North by Northwest  1959         Patrick McVey    actor   \n",
       "176953   North by Northwest  1959          Edward Binns    actor   \n",
       "1202896  North by Northwest  1959             Ken Lynch    actor   \n",
       "\n",
       "                           character   n  \n",
       "757365            Roger O. Thornhill   1  \n",
       "3017825                  Eve Kendall   2  \n",
       "1265989              Phillip Vandamm   3  \n",
       "2716993              Clara Thornhill   4  \n",
       "308625                 The Professor   5  \n",
       "2627970                Mrs. Townsend   6  \n",
       "1473804              Lester Townsend   7  \n",
       "1107146                      Leonard   8  \n",
       "2122318                     Valerian   9  \n",
       "1573755              Victor Larrabee  10  \n",
       "578418                         Licht  11  \n",
       "1990909                   Auctioneer  12  \n",
       "402492                     Dr. Cross  13  \n",
       "1311473               Sergeant Flamm  14  \n",
       "176953                Captain Junket  15  \n",
       "1202896  Charley - Chicago Policeman  16  "
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Display the cast of \"North by Northwest\" in their correct \"n\"-value order,\n",
    "# ignoring roles that did not earn a numeric \"n\" value.\n",
    "\n",
    "c = cast\n",
    "c = c[c.title == 'North by Northwest']\n",
    "c = c[c.n.notnull()]\n",
    "c = c.sort_values('n')\n",
    "c"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div style=\"max-height:1000px;max-width:1500px;overflow:auto;\">\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>title</th>\n",
       "      <th>year</th>\n",
       "      <th>name</th>\n",
       "      <th>type</th>\n",
       "      <th>character</th>\n",
       "      <th>n</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1482373</th>\n",
       "      <td>Sleuth</td>\n",
       "      <td>1972</td>\n",
       "      <td>Laurence Olivier</td>\n",
       "      <td>actor</td>\n",
       "      <td>Andrew Wyke</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>282327</th>\n",
       "      <td>Sleuth</td>\n",
       "      <td>1972</td>\n",
       "      <td>Michael Caine</td>\n",
       "      <td>actor</td>\n",
       "      <td>Milo Tindle</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>323726</th>\n",
       "      <td>Sleuth</td>\n",
       "      <td>1972</td>\n",
       "      <td>Alec Cawthorne</td>\n",
       "      <td>actor</td>\n",
       "      <td>Inspector Doppler</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1273111</th>\n",
       "      <td>Sleuth</td>\n",
       "      <td>1972</td>\n",
       "      <td>John (II) Matthews</td>\n",
       "      <td>actor</td>\n",
       "      <td>Detective Sergeant Tarrant</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2356004</th>\n",
       "      <td>Sleuth</td>\n",
       "      <td>1972</td>\n",
       "      <td>Eve (III) Channing</td>\n",
       "      <td>actress</td>\n",
       "      <td>Marguerite Wyke</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1258789</th>\n",
       "      <td>Sleuth</td>\n",
       "      <td>1972</td>\n",
       "      <td>Teddy Martin</td>\n",
       "      <td>actor</td>\n",
       "      <td>Police Constable Higgs</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          title  year                name     type  \\\n",
       "1482373  Sleuth  1972    Laurence Olivier    actor   \n",
       "282327   Sleuth  1972       Michael Caine    actor   \n",
       "323726   Sleuth  1972      Alec Cawthorne    actor   \n",
       "1273111  Sleuth  1972  John (II) Matthews    actor   \n",
       "2356004  Sleuth  1972  Eve (III) Channing  actress   \n",
       "1258789  Sleuth  1972        Teddy Martin    actor   \n",
       "\n",
       "                          character  n  \n",
       "1482373                 Andrew Wyke  1  \n",
       "282327                  Milo Tindle  2  \n",
       "323726            Inspector Doppler  3  \n",
       "1273111  Detective Sergeant Tarrant  4  \n",
       "2356004             Marguerite Wyke  5  \n",
       "1258789      Police Constable Higgs  6  "
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Display the entire cast, in \"n\"-order, of the 1972 film \"Sleuth\".\n",
    "\n",
    "c = cast\n",
    "c = c[c.title == 'Sleuth']\n",
    "c = c[c.year == 1972]\n",
    "c = c.sort_values('n')\n",
    "c"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div style=\"max-height:1000px;max-width:1500px;overflow:auto;\">\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>title</th>\n",
       "      <th>year</th>\n",
       "      <th>name</th>\n",
       "      <th>type</th>\n",
       "      <th>character</th>\n",
       "      <th>n</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>282328</th>\n",
       "      <td>Sleuth</td>\n",
       "      <td>2007</td>\n",
       "      <td>Michael Caine</td>\n",
       "      <td>actor</td>\n",
       "      <td>Andrew</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1123295</th>\n",
       "      <td>Sleuth</td>\n",
       "      <td>2007</td>\n",
       "      <td>Jude Law</td>\n",
       "      <td>actor</td>\n",
       "      <td>Milo</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1569094</th>\n",
       "      <td>Sleuth</td>\n",
       "      <td>2007</td>\n",
       "      <td>Harold Pinter</td>\n",
       "      <td>actor</td>\n",
       "      <td>Man on T.V.</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>223724</th>\n",
       "      <td>Sleuth</td>\n",
       "      <td>2007</td>\n",
       "      <td>Kenneth Branagh</td>\n",
       "      <td>actor</td>\n",
       "      <td>Other Man on T.V.</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>323727</th>\n",
       "      <td>Sleuth</td>\n",
       "      <td>2007</td>\n",
       "      <td>Alec (II) Cawthorne</td>\n",
       "      <td>actor</td>\n",
       "      <td>Inspector Doppler</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2356003</th>\n",
       "      <td>Sleuth</td>\n",
       "      <td>2007</td>\n",
       "      <td>Eve (II) Channing</td>\n",
       "      <td>actress</td>\n",
       "      <td>Marguerite Wyke</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2895151</th>\n",
       "      <td>Sleuth</td>\n",
       "      <td>2007</td>\n",
       "      <td>Carmel O'Sullivan</td>\n",
       "      <td>actress</td>\n",
       "      <td>Maggie</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          title  year                 name     type          character   n\n",
       "282328   Sleuth  2007        Michael Caine    actor             Andrew   1\n",
       "1123295  Sleuth  2007             Jude Law    actor               Milo   2\n",
       "1569094  Sleuth  2007        Harold Pinter    actor        Man on T.V.   3\n",
       "223724   Sleuth  2007      Kenneth Branagh    actor  Other Man on T.V. NaN\n",
       "323727   Sleuth  2007  Alec (II) Cawthorne    actor  Inspector Doppler NaN\n",
       "2356003  Sleuth  2007    Eve (II) Channing  actress    Marguerite Wyke NaN\n",
       "2895151  Sleuth  2007    Carmel O'Sullivan  actress             Maggie NaN"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Now display the entire cast, in \"n\"-order, of the 2007 version of \"Sleuth\".\n",
    "\n",
    "c = cast\n",
    "c = c[c.title == 'Sleuth']\n",
    "c = c[c.year == 2007]\n",
    "c = c.sort_values('n')\n",
    "c"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "9"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# How many roles were credited in the silent 1921 version of Hamlet?\n",
    "\n",
    "c = cast\n",
    "c = c[(c.title == 'Hamlet') & (c.year == 1921)]\n",
    "len(c)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "55"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# How many roles were credited in Branagh’s 1996 Hamlet?\n",
    "\n",
    "c = cast\n",
    "c = c[(c.title == 'Hamlet') & (c.year == 1996)]\n",
    "len(c)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "81"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# How many \"Hamlet\" roles have been listed in all film credits through history?\n",
    "\n",
    "c = cast\n",
    "c = c[c.character == 'Hamlet']\n",
    "len(c)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "93"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# How many people have played an \"Ophelia\"?\n",
    "\n",
    "c = cast\n",
    "c = c[c.character == 'Ophelia']\n",
    "len(c)\n",
    "\n",
    "# That was my original answer.\n",
    "# But 9peppe on GitHub points out I am wrong! Instead:\n",
    "\n",
    "len(cast[cast.character == \"Ophelia\"].name.unique())\n",
    "\n",
    "# Can you work out why the two answers are different?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "16"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# How many people have played a role called \"The Dude\"?\n",
    "\n",
    "c = cast\n",
    "c = c[c.character == 'The Dude'].name.unique()\n",
    "len(c)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "186"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# How many people have played a role called \"The Stranger\"?\n",
    "\n",
    "c = cast\n",
    "len(c[c.character == 'The Stranger'].name.unique())\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "43"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# How many roles has Sidney Poitier played throughout his career?\n",
    "\n",
    "c = cast\n",
    "c = c[c.name == 'Sidney Poitier']\n",
    "len(c)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "51"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# How many roles has Judi Dench played?\n",
    "\n",
    "c = cast\n",
    "c = c[c.name == 'Judi Dench']\n",
    "len(c)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div style=\"max-height:1000px;max-width:1500px;overflow:auto;\">\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>title</th>\n",
       "      <th>year</th>\n",
       "      <th>name</th>\n",
       "      <th>type</th>\n",
       "      <th>character</th>\n",
       "      <th>n</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>757362</th>\n",
       "      <td>My Favorite Wife</td>\n",
       "      <td>1940</td>\n",
       "      <td>Cary Grant</td>\n",
       "      <td>actor</td>\n",
       "      <td>Nick</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>757372</th>\n",
       "      <td>Penny Serenade</td>\n",
       "      <td>1941</td>\n",
       "      <td>Cary Grant</td>\n",
       "      <td>actor</td>\n",
       "      <td>Roger Adams</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                   title  year        name   type    character  n\n",
       "757362  My Favorite Wife  1940  Cary Grant  actor         Nick  2\n",
       "757372    Penny Serenade  1941  Cary Grant  actor  Roger Adams  2"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# List the supporting roles (having n=2) played by Cary Grant in the 1940s,\n",
    "# in order by year.\n",
    "\n",
    "c = cast\n",
    "c = c[c.name == 'Cary Grant']\n",
    "c = c[c.year // 10 == 194]\n",
    "c = c[c.n == 2]\n",
    "c = c.sort_values('year')\n",
    "c"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div style=\"max-height:1000px;max-width:1500px;overflow:auto;\">\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>title</th>\n",
       "      <th>year</th>\n",
       "      <th>name</th>\n",
       "      <th>type</th>\n",
       "      <th>character</th>\n",
       "      <th>n</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>757387</th>\n",
       "      <td>The Howards of Virginia</td>\n",
       "      <td>1940</td>\n",
       "      <td>Cary Grant</td>\n",
       "      <td>actor</td>\n",
       "      <td>Matt Howard</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>757344</th>\n",
       "      <td>His Girl Friday</td>\n",
       "      <td>1940</td>\n",
       "      <td>Cary Grant</td>\n",
       "      <td>actor</td>\n",
       "      <td>Walter Burns</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>757389</th>\n",
       "      <td>The Philadelphia Story</td>\n",
       "      <td>1940</td>\n",
       "      <td>Cary Grant</td>\n",
       "      <td>actor</td>\n",
       "      <td>C.K. Dexter Haven</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>757377</th>\n",
       "      <td>Suspicion</td>\n",
       "      <td>1941</td>\n",
       "      <td>Cary Grant</td>\n",
       "      <td>actor</td>\n",
       "      <td>Johnnie</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>757391</th>\n",
       "      <td>The Talk of the Town</td>\n",
       "      <td>1942</td>\n",
       "      <td>Cary Grant</td>\n",
       "      <td>actor</td>\n",
       "      <td>Leopold Dilg</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>757368</th>\n",
       "      <td>Once Upon a Honeymoon</td>\n",
       "      <td>1942</td>\n",
       "      <td>Cary Grant</td>\n",
       "      <td>actor</td>\n",
       "      <td>Patrick 'Pat' O'Toole</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>757335</th>\n",
       "      <td>Destination Tokyo</td>\n",
       "      <td>1943</td>\n",
       "      <td>Cary Grant</td>\n",
       "      <td>actor</td>\n",
       "      <td>Capt. Cassidy</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>757360</th>\n",
       "      <td>Mr. Lucky</td>\n",
       "      <td>1943</td>\n",
       "      <td>Cary Grant</td>\n",
       "      <td>actor</td>\n",
       "      <td>Joe Adams</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>757361</th>\n",
       "      <td>Mr. Lucky</td>\n",
       "      <td>1943</td>\n",
       "      <td>Cary Grant</td>\n",
       "      <td>actor</td>\n",
       "      <td>Joe Bascopolous</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>757369</th>\n",
       "      <td>Once Upon a Time</td>\n",
       "      <td>1944</td>\n",
       "      <td>Cary Grant</td>\n",
       "      <td>actor</td>\n",
       "      <td>Jerry Flynn</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>757327</th>\n",
       "      <td>Arsenic and Old Lace</td>\n",
       "      <td>1944</td>\n",
       "      <td>Cary Grant</td>\n",
       "      <td>actor</td>\n",
       "      <td>Mortimer Brewster</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>757364</th>\n",
       "      <td>None But the Lonely Heart</td>\n",
       "      <td>1944</td>\n",
       "      <td>Cary Grant</td>\n",
       "      <td>actor</td>\n",
       "      <td>Ernie Mott</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>757363</th>\n",
       "      <td>Night and Day</td>\n",
       "      <td>1946</td>\n",
       "      <td>Cary Grant</td>\n",
       "      <td>actor</td>\n",
       "      <td>Cole Porter</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>757366</th>\n",
       "      <td>Notorious</td>\n",
       "      <td>1946</td>\n",
       "      <td>Cary Grant</td>\n",
       "      <td>actor</td>\n",
       "      <td>Devlin</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>757383</th>\n",
       "      <td>The Bachelor and the Bobby-Soxer</td>\n",
       "      <td>1947</td>\n",
       "      <td>Cary Grant</td>\n",
       "      <td>actor</td>\n",
       "      <td>Dick</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>757384</th>\n",
       "      <td>The Bishop's Wife</td>\n",
       "      <td>1947</td>\n",
       "      <td>Cary Grant</td>\n",
       "      <td>actor</td>\n",
       "      <td>Dudley</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>757359</th>\n",
       "      <td>Mr. Blandings Builds His Dream House</td>\n",
       "      <td>1948</td>\n",
       "      <td>Cary Grant</td>\n",
       "      <td>actor</td>\n",
       "      <td>Jim Blandings</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>757339</th>\n",
       "      <td>Every Girl Should Be Married</td>\n",
       "      <td>1948</td>\n",
       "      <td>Cary Grant</td>\n",
       "      <td>actor</td>\n",
       "      <td>Dr. Madison Brown</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>757348</th>\n",
       "      <td>I Was a Male War Bride</td>\n",
       "      <td>1949</td>\n",
       "      <td>Cary Grant</td>\n",
       "      <td>actor</td>\n",
       "      <td>Capt. Henri Rochard</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                       title  year        name   type  \\\n",
       "757387               The Howards of Virginia  1940  Cary Grant  actor   \n",
       "757344                       His Girl Friday  1940  Cary Grant  actor   \n",
       "757389                The Philadelphia Story  1940  Cary Grant  actor   \n",
       "757377                             Suspicion  1941  Cary Grant  actor   \n",
       "757391                  The Talk of the Town  1942  Cary Grant  actor   \n",
       "757368                 Once Upon a Honeymoon  1942  Cary Grant  actor   \n",
       "757335                     Destination Tokyo  1943  Cary Grant  actor   \n",
       "757360                             Mr. Lucky  1943  Cary Grant  actor   \n",
       "757361                             Mr. Lucky  1943  Cary Grant  actor   \n",
       "757369                      Once Upon a Time  1944  Cary Grant  actor   \n",
       "757327                  Arsenic and Old Lace  1944  Cary Grant  actor   \n",
       "757364             None But the Lonely Heart  1944  Cary Grant  actor   \n",
       "757363                         Night and Day  1946  Cary Grant  actor   \n",
       "757366                             Notorious  1946  Cary Grant  actor   \n",
       "757383      The Bachelor and the Bobby-Soxer  1947  Cary Grant  actor   \n",
       "757384                     The Bishop's Wife  1947  Cary Grant  actor   \n",
       "757359  Mr. Blandings Builds His Dream House  1948  Cary Grant  actor   \n",
       "757339          Every Girl Should Be Married  1948  Cary Grant  actor   \n",
       "757348                I Was a Male War Bride  1949  Cary Grant  actor   \n",
       "\n",
       "                    character  n  \n",
       "757387            Matt Howard  1  \n",
       "757344           Walter Burns  1  \n",
       "757389      C.K. Dexter Haven  1  \n",
       "757377                Johnnie  1  \n",
       "757391           Leopold Dilg  1  \n",
       "757368  Patrick 'Pat' O'Toole  1  \n",
       "757335          Capt. Cassidy  1  \n",
       "757360              Joe Adams  1  \n",
       "757361        Joe Bascopolous  1  \n",
       "757369            Jerry Flynn  1  \n",
       "757327      Mortimer Brewster  1  \n",
       "757364             Ernie Mott  1  \n",
       "757363            Cole Porter  1  \n",
       "757366                 Devlin  1  \n",
       "757383                   Dick  1  \n",
       "757384                 Dudley  1  \n",
       "757359          Jim Blandings  1  \n",
       "757339      Dr. Madison Brown  1  \n",
       "757348    Capt. Henri Rochard  1  "
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# List the leading roles that Cary Grant played in the 1940s in order by year.\n",
    "\n",
    "c = cast\n",
    "c = c[c.name == 'Cary Grant']\n",
    "c = c[c.year // 10 == 194]\n",
    "c = c[c.n == 1 ]\n",
    "c = c.sort_values('year')\n",
    "c"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "146164"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# How many roles were available for actors in the 1950s?\n",
    "\n",
    "c = cast\n",
    "c = c[c.year // 10 == 195]\n",
    "c = c[c.type == 'actor']\n",
    "len(c)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "53430"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# How many roles were available for actresses in the 1950s?\n",
    "\n",
    "c = cast\n",
    "c = c[c.year // 10 == 195]\n",
    "c = c[c.type == 'actress']\n",
    "len(c)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "61005"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# How many leading roles (n=1) were available\n",
    "# from the beginning of film history through 1980?\n",
    "\n",
    "c = cast\n",
    "c = c[c.year <= 1980]\n",
    "c = c[c.n == 1]\n",
    "len(c)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1037396"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# How many non-leading roles were available through\n",
    "# from the beginning of film history through 1980?\n",
    "\n",
    "c = cast\n",
    "c = c[c.year <= 1980]\n",
    "c = c[c.n != 1]\n",
    "len(c)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "409437"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# How many roles through 1980 were minor enough\n",
    "# that they did not warrant a numeric \"n\" rank?\n",
    "\n",
    "c = cast\n",
    "c = c[c.year <= 1980]\n",
    "c = c[c.n.isnull()]\n",
    "len(c)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
